home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / srgp / src / oldcolor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-11  |  6.3 KB  |  230 lines

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3.  
  4. /** THIS FILE IS FOR X11 IMPLEMENTATION ONLY
  5. **/
  6.  
  7. void 
  8. SRGP__initColor (requested_planes)
  9. {
  10.    srgp__available_depth = DefaultDepth(srgpx__display, srgpx__screen);
  11.  
  12.    if (srgp__available_depth == 1) {
  13.  
  14.       /***** PERFORMED FOR BILEVEL DISPLAYS */
  15.  
  16.       SRGP_BLACK = BlackPixel(srgpx__display,srgpx__screen);
  17.       SRGP_WHITE = WhitePixel(srgpx__display,srgpx__screen);
  18.       srgp__application_depth = 
  19.      srgp__max_pixel_value = 1;
  20.       srgp__base_colorindex = 0;
  21.    }
  22.    
  23.  
  24.    else {
  25.  
  26.       /****** PERFORMED FOR COLOR DISPLAYS */
  27.  
  28.       SRGP_BLACK = 1;
  29.       SRGP_WHITE = 0;
  30.  
  31.       if (requested_planes < 0) {
  32.      fprintf (stderr, "Fatal Error: insane parameter to SRGP_begin()\n\
  33.             Application requesting negative number of planes.\n");
  34.      exit(1);
  35.       }
  36.       if ((requested_planes == 0) || 
  37.       (requested_planes > srgp__available_depth)) 
  38.      srgp__application_depth = srgp__available_depth;
  39.       else
  40.      srgp__application_depth = requested_planes;
  41.       srgp__max_pixel_value = (1 << srgp__application_depth) - 1;
  42.  
  43.       if (srgp__application_depth == srgp__available_depth) {
  44.  
  45.      /***** APPL WANTS ENTIRE COLOR TABLE! */
  46.      srgpx__colormap = 
  47.         XCreateColormap (srgpx__display, 
  48.                  srgp__curActiveCanvasSpec.drawable.win,
  49.                  DefaultVisual(srgpx__display,srgpx__screen),
  50.                  AllocAll);
  51.      XSetWindowColormap (srgpx__display, 
  52.                  srgp__curActiveCanvasSpec.drawable.win,
  53.                  srgpx__colormap);
  54.       }
  55.       else {
  56.  
  57.      /***** APPL WANTS TO SHARE COLOR TABLE WITH THE OTHER CLIENTS */
  58.      unsigned long return_masks_here[8];
  59.      unsigned long return_pixels_here[1];
  60.      Status result;
  61.  
  62.      srgpx__colormap = DefaultColormap(srgpx__display,srgpx__screen);
  63.  
  64.      result = 
  65.         XAllocColorCells (srgpx__display,
  66.                   srgpx__colormap,
  67.                   TRUE /* contiguous planes desired */,
  68.                   return_masks_here,
  69.                   srgp__application_depth,
  70.                   return_pixels_here,
  71.                   1);
  72.      if (result == 0) {
  73.         fprintf (stderr, "%s\n%s\n%s\n%s\n%s\n",
  74.              "Fatal error: Color table too full to share.",
  75.              "A solution is to have the SRGP application request",
  76.              "   0 planes in the 4th parameter to SRGP_begin.",
  77.              "This gives SRGP permission to use its own complete",
  78.              "   color table, rather than try to share.");
  79.         exit(1);
  80.      }
  81.      
  82.      srgp__base_colorindex = return_pixels_here[0];
  83.       }
  84.  
  85.       /* Only first two entries of LUT are init'd */
  86.       XStoreNamedColor 
  87.      (srgpx__display, srgpx__colormap, "white", COLORINDEX(0), -1);
  88.       XStoreNamedColor 
  89.      (srgpx__display, srgpx__colormap, "black", COLORINDEX(1), -1);
  90.    }
  91.  
  92.  
  93.    /*** DONE FOR ALL CONFIGURATIONS. */
  94.    XSetWindowBackground (srgpx__display, 
  95.              srgp__curActiveCanvasSpec.drawable.win, 0);
  96.    XSetWindowBorder (srgpx__display, 
  97.              srgp__curActiveCanvasSpec.drawable.win, 1);
  98. }
  99.  
  100.  
  101.  
  102. void SRGP_loadColorTable
  103.    (int startentry, int count,
  104.     unsigned short *redi, 
  105.     unsigned short *greeni,
  106.     unsigned short *bluei)
  107. {
  108.    static XColor *x_color_structs = NULL;
  109.    static int cursize_of_x_cs_array = 0;  /* number of XColor structs */
  110.    register int i,j;
  111.    int endi;
  112.    register XColor *xcurcs;
  113.  
  114.  
  115.    /* LEAVE IMMEDIATELY IF EXECUTING ON BILEVEL DISPLAY */
  116.    if (srgp__available_depth == 1)
  117.       return;
  118.  
  119.    endi = startentry + count;
  120.  
  121.    DEBUG_AIDS{
  122.       SRGP_trace (SRGP_logStream, "SRGP_loadColorTable  %d  %d  %x %x %x\n",
  123.           startentry, count, redi, greeni, bluei);
  124.  
  125.       /* PERFORM CHECKING LEGALITY OF THE RANGE OF INDICES. */
  126.       srgp_check_pixel_value (startentry, "start");
  127.       srgp_check_pixel_value (endi-1, "end");
  128.    }
  129.  
  130.  
  131.    /* DYNAMICALLY (RE)ALLOCATE ARRAY OF XColor STRUCTURES */
  132.    if (cursize_of_x_cs_array < count) {
  133.       if (x_color_structs)
  134.      free ((char*)x_color_structs);
  135.       x_color_structs = (XColor*) malloc (sizeof(XColor)*count);
  136.       cursize_of_x_cs_array = count;
  137.  
  138.       /* Initialize a constant field of the XColor structs. */
  139.       for (i=0; i<count; i++)
  140.      x_color_structs[i].flags = -1;
  141.    }
  142.  
  143.    /* COPY INTENSITY VALUES INTO ARRAY. */
  144.    for (i=startentry, j=0, xcurcs=x_color_structs; i<endi; i++,j++,xcurcs++){
  145.       xcurcs->pixel = COLORINDEX(i);
  146.       xcurcs->red = redi[j];
  147.       xcurcs->green = greeni[j];
  148.       xcurcs->blue = bluei[j];
  149.    }
  150.  
  151.    XStoreColors (srgpx__display, srgpx__colormap, x_color_structs, count);
  152. }
  153.  
  154.  
  155.  
  156.  
  157. void
  158. SRGP_inquireColorTable 
  159.    (int startentry, int count,
  160.     unsigned short *redi, 
  161.     unsigned short *greeni,
  162.     unsigned short *bluei)
  163. {
  164.    static XColor *x_color_structs = NULL;
  165.    static int cursize_of_x_cs_array = 0;  /* number of XColor structs */
  166.    register int i,j;
  167.    int endi;
  168.    register XColor *xcurcs;
  169.  
  170.  
  171.    /* LEAVE IMMEDIATELY IF EXECUTING ON BILEVEL DISPLAY */
  172.    if (srgp__available_depth == 1)
  173.       return;
  174.  
  175.    endi = startentry + count;
  176.  
  177.    DEBUG_AIDS{
  178.       /* PERFORM CHECKING LEGALITY OF THE RANGE OF INDICES. */
  179.       srgp_check_pixel_value (startentry, "start");
  180.       srgp_check_pixel_value (endi-1, "end");
  181.    }
  182.  
  183.  
  184.    /* !!!!!! LATER, THIS SHOULD USE SAME ARRAY AS IN color_X11.c */
  185.  
  186.    /* DYNAMICALLY (RE)ALLOCATE ARRAY OF XColor STRUCTURES */
  187.    if (cursize_of_x_cs_array < count) {
  188.       if (x_color_structs)
  189.      free ((char*)x_color_structs);
  190.       x_color_structs = (XColor*) malloc (sizeof(XColor)*count);
  191.       cursize_of_x_cs_array = count;
  192.    }
  193.  
  194.    for (i=startentry, xcurcs=x_color_structs; i<endi; i++,xcurcs++) {
  195.       xcurcs->pixel = COLORINDEX(i);
  196.       xcurcs->flags = -1;
  197.    }
  198.  
  199.    XQueryColors (srgpx__display, srgpx__colormap, x_color_structs, count);
  200.  
  201.  
  202.    /* COPY INTENSITY VALUES INTO USER'S ARRAY. */
  203.    for (j=0, xcurcs=x_color_structs; j<count; j++,xcurcs++){
  204.       redi[j] = xcurcs->red;
  205.       greeni[j] = xcurcs->green;
  206.       bluei[j] = xcurcs->blue;
  207.    }
  208. }
  209.  
  210.  
  211.  
  212.  
  213. void
  214. SRGP_loadCommonColor (entry, name)
  215. int entry;
  216. char *name;   /* Null-terminated string of characters */
  217. {
  218.    /* IGNORE IF MONOCHROME */
  219.    if (srgp__available_depth == 1)
  220.       return;
  221.  
  222.    DEBUG_AIDS{
  223.       SRGP_trace (SRGP_logStream, "SRGP_loadCommonColor  %d  %s\n", entry, name);
  224.       srgp_check_pixel_value (entry, "start/end");
  225.    }
  226.  
  227.    XStoreNamedColor 
  228.       (srgpx__display, srgpx__colormap, name, COLORINDEX(entry), -1);
  229. }
  230.